public class test {
    //链表的回文结构:思路：找到中间结点，并将后面结点进行倒置（有三个注意点：1.空链表 2.如何倒置后面的结点，slow不能等于slow.next 3.偶数的结束cur.next == slow
    public boolean chkPalindrome(ListNode A) {
    //空链表
    if(A == null) {
        return true;
    }
    //快慢指针找中间结点(偶数slow走到的是后面的结点)
    ListNode fast =A;
    ListNode slow =A;
    while(fast != null&&fast.next != null) {
        fast = fast.next.next;
        slow = slow.next;
    }

    //将后面的结点进行倒置
    ListNode cur = slow.next;
    while(cur != null) {
        ListNode curNext = cur.next;//用来记录cur的下一个结点
        cur.next =slow;
        slow = cur;//这里slow不能等于slow.next，已经变了
        cur = curNext;
    }

    //然后一一进行判断
    cur = A;
    while(cur != slow) {
        if(cur.val != slow.val) {
            return false;
        } else {
            //偶数的情况
            if(cur.next == slow) {
                return true;
            }
            cur = cur.next;
            slow = slow.next;
        }
    }
    return true;
}
}
